package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ConnectionFabric {    

	private static Connection conn;
	/**
	 * @param args
	 * @throws SQLException 
	 */
	public static Connection getConnection() throws SQLException{
		

        String      url         = "jdbc:mysql://localhost/JVendor";
        String      userName    = "root";  // blanked for publication
        String      password    = "deadly";
		
        try {     
            Class.forName("com.mysql.jdbc.Driver");         
            conn = DriverManager.getConnection(url,userName,password); 
         
        }catch(Exception ex){
        ex.printStackTrace();
        }
		return conn;
       
        }
	public static int getAutoInc(String Generator) {
        int Codigo = 0;
        try {
            PreparedStatement pstmt = conn.prepareStatement(
                    "Select Gen_ID("+Generator+",1) From RDB$Database");
            //pstmt.setString(1, Generator);
            ResultSet rs = pstmt.executeQuery();
            rs.next();
            Codigo = rs.getInt(1);
           
        }catch(Exception ex){
        	ex.printStackTrace();
        	
        }
		return Codigo;
	
	}
}

